package cn.edu.usst.cs.goldfish.booking.meetingroom.util;

import cn.edu.usst.cs.goldfish.booking.meetingroom.web.dto.booking.Slot;
import org.springframework.stereotype.Component;

import java.time.*;
import java.util.*;
@Component
public class SlotUtil {
    public static List<Slot> computeSlotsBetween(Long roomId, LocalDateTime start, LocalDateTime end) {
        List<Slot> result = new ArrayList<>();
        LocalDateTime cursor = start;

        while (cursor.isBefore(end)) {
            Slot.SlotBuilder builder = Slot.builder()
                    .roomId(roomId)
                    .date(cursor.toLocalDate());
            short hour = (short) cursor.getHour();
            builder.hour(hour);
            short segment = (short) (cursor.getMinute() / 10 + 1);
            builder.segment(segment);
            result.add(builder.build());
            cursor = cursor.plusMinutes(10);
        }

        return result;
    }
}
